using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DTO;
using BUS;

namespace TTNgoaiNguSuPham
{
    public partial class frmTimKiem_CapNhat : Form
    {
        public frmTimKiem_CapNhat()
        {
            InitializeComponent();
        }

        private void btnTim_Click(object sender, EventArgs e)
        {
            try
            {
                DataTable dt = new DataTable();
                ThiSinh_BUS ts_bus = new ThiSinh_BUS();
                float DTB = 0;
                int MaTS = Convert.ToInt32(txtMaTS.Text);

                Double start = DateTime.Now.TimeOfDay.TotalMilliseconds;
                dt = ts_bus.TraCuuTTDuThi(MaTS, ref DTB);
                Double finish = DateTime.Now.TimeOfDay.TotalMilliseconds;
                int delta = Convert.ToInt32(finish - start);
                lblThoiGianTim.Text = delta.ToString();

                dtgvDiem_TS.DataSource = dt;
                lblDTB.Text = DTB.ToString();
                txtDiemVong1.Text = dt.Rows[0]["Diem"].ToString();
                txtDiemViet.Text = dt.Rows[0]["DiemViet"].ToString();
                txtDiemNoi.Text = dt.Rows[0]["DiemNoi"].ToString();
                txtDiemNghe.Text = dt.Rows[0]["DiemNghe"].ToString();
            }
            catch (SqlException sql)
            {
                MessageBox.Show(sql.Message);
            }
        }

        private void btnfrmTNTS_Click(object sender, EventArgs e)
        {
            this.Hide();
            frmTNTS frm = new frmTNTS();
            frm.ShowDialog();
        }

        private void btnfrmBCTK_Click(object sender, EventArgs e)
        {
            this.Hide();
            frmBCTK frm = new frmBCTK();
            frm.ShowDialog();
        }

        private void btnCapNhat_Click(object sender, EventArgs e)
        {
            try
            {
                ThiSinh_BUS tsbus = new ThiSinh_BUS();
                int MaTS = int.Parse(txtMaTS.Text);
                float diem = float.Parse(txtDiemVong1.Text);
                float diemnoi = float.Parse(txtDiemNoi.Text);
                float diemviet = float.Parse(txtDiemViet.Text);
                float diemnghe = float.Parse(txtDiemNghe.Text);

                Double start = DateTime.Now.TimeOfDay.TotalMilliseconds;
                tsbus.CapNhatDiem(MaTS, diem, diemnoi, diemviet, diemnghe);
                Double finish = DateTime.Now.TimeOfDay.TotalMilliseconds;
                int delta = Convert.ToInt32(finish - start);
                lblThoiGianCapNhat.Text = delta.ToString();

                DataTable dt = new DataTable();
                float DTB = 0;
                
                dt = tsbus.TraCuuTTDuThi(MaTS, ref DTB);
                dtgvDiem_TS.DataSource = dt;
                lblDTB.Text = DTB.ToString();

                MessageBox.Show("Cap nhat thanh cong");

            }
            catch (SqlException sql)
            {
                MessageBox.Show(sql.Message);
            }
        }

       
    }
}